from khronos.statistics import TSeries

class Indicator(object):
    """Base class for experiment indicators. This cannot be used off-the-shelf since it provides 
    no data collection functionality. For automatic data gathering from an experiment, see 
    StatIndicator below. Users can also subclass from this class, but they must ensure to write 
    new start(), end(), run_start(), and run_end() methods. The constructor should maintain the 
    same signature, since indicator instances are created automatically by experiment objects, 
    taking the experiment object as its only argument."""
    def __init__(self, experiment):
        self.experiment = experiment
        
    def start(self): pass
    def end(self): pass
    def run_start(self): pass
    def run_end(self): pass
    
class StatIndicator(Indicator):
    """Statical indicator class. This class must be subclassed, defining a get() method to 
    collect data from the current state of a given experiment."""
    storing = True
    numeric = True
    
    def start(self):
        self.stat = TSeries(storing=self.storing, numeric=self.numeric)
        
    def run_end(self):
        self.stat.collect(self.get(), self.stat.count())
        
    def get(self):
        raise NotImplementedError()
        
